﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SGRapidForm.Common;
using System.Collections.Specialized;
using FishWebLib;
using SGRapidForm.Permission.Entity;
using System.Data;

namespace SGRapidForm.Permission.Component
{
    public class RoleModuleComponent : ComponentBase
    {
        public bool RoleModule_Add(string roleKeyid, string moduleKeyid)
        {
            return FishBLLHelper.CallSpExecuteNonQuery("sgrf_permission_RoleModule_Add", null, roleKeyid, moduleKeyid) > 0;
        }

        public bool RoleModule_Delete(string roleKeyid, string moduleKeyid)
        {
            return FishBLLHelper.CallSpExecuteNonQuery("sgrf_permission_RoleModule_Delete", null, roleKeyid, moduleKeyid) > 0;
        }

        public bool RoleModule_DeleteByRoleKeyid(string roleKeyid)
        {
            return FishBLLHelper.CallSpExecuteNonQuery("sgrf_permission_RoleModule_DeleteByRoleKeyid", null, roleKeyid) > 0;
        }

        public List<PermissionDetails> RoleModule_GetDetailsByRoleKeyid(string roleKeyid)
        {
            return FishBLLHelper.CallSpGetDataItemList<PermissionDetails>("sgrf_permission_RoleModule_GetDetailsByRoleKeyid", null, roleKeyid);  
        }



        /// <summary>
        /// 为岗位添加模块
        /// </summary>
        /// <param name="roleKeyid">岗位Keyid</param>
        /// <param name="moduleKeyids">模块Keyid集合</param>
        /// <returns></returns>
        public bool RoleModule_BulkAdd(string roleKeyid, string[] moduleKeyids)
        {
            /*
                1,删除与岗位相关信息
                2,重新分配模块
             */

            //1,删除与岗位相关信息
            FishBLLHelper.CallSpExecuteNonQuery("sgrf_permission_RoleModule_DeleteByRoleKeyid", null, roleKeyid);

            //2,重新分配模块
            foreach (string moduleKeyid in moduleKeyids)
            {
                FishBLLHelper.CallSpExecuteNonQuery("sgrf_permission_RoleModule_Add", null, roleKeyid, moduleKeyid);
            }

            return true;
        }
    }
}
